package com.ruoyi.student.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.student.domain.vo.TSpecialityVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.student.domain.TSpeciality;
import com.ruoyi.student.service.ITSpecialityService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 专业Controller
 * 
 * @author ruoyi
 * @date 2023-08-15
 */
@RestController
@RequestMapping("/student/speciality")
public class TSpecialityController extends BaseController
{
    @Autowired
    private ITSpecialityService tSpecialityService;

    /**
     * 查询专业列表
     */
    @PreAuthorize("@ss.hasPermi('student:speciality:list')")
    @GetMapping("/list")
    public TableDataInfo list(TSpeciality tSpeciality)
    {
        startPage();
//        List<TSpeciality> list = tSpecialityService.selectTSpecialityList(tSpeciality);
        List<TSpecialityVo> list = tSpecialityService.selectTSpecialityVoList(tSpeciality);
        return getDataTable(list);
    }

    /**
     * 导出专业列表
     */
    @PreAuthorize("@ss.hasPermi('student:speciality:export')")
    @Log(title = "专业", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TSpeciality tSpeciality)
    {
        List<TSpeciality> list = tSpecialityService.selectTSpecialityList(tSpeciality);
        ExcelUtil<TSpeciality> util = new ExcelUtil<TSpeciality>(TSpeciality.class);
        util.exportExcel(response, list, "专业数据");
    }

    /**
     * 获取专业详细信息
     */
    @PreAuthorize("@ss.hasPermi('student:speciality:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tSpecialityService.selectTSpecialityById(id));
    }

    /**
     * 新增专业
     */
    @PreAuthorize("@ss.hasPermi('student:speciality:add')")
    @Log(title = "专业", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TSpeciality tSpeciality)
    {
        SysUser user = SecurityUtils.getLoginUser().getUser();
        tSpeciality.setCreatorId(user.getUserId());
        return toAjax(tSpecialityService.insertTSpeciality(tSpeciality));
    }

    /**
     * 修改专业
     */
    @PreAuthorize("@ss.hasPermi('student:speciality:edit')")
    @Log(title = "专业", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TSpeciality tSpeciality)
    {
        return toAjax(tSpecialityService.updateTSpeciality(tSpeciality));
    }

    /**
     * 删除专业
     */
    @PreAuthorize("@ss.hasPermi('student:speciality:remove')")
    @Log(title = "专业", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tSpecialityService.deleteTSpecialityByIds(ids));
    }
}
